#include "cProgressbar.h"

cProgressbar::cProgressbar(cHwnd * hwndParent,int x,int y,int largeur,int hauteur,cHwnd * HWNDParent):
        cControl(hwndParent)
{
    //ctor
    HWND leParent=hwndParent->getHwnd();
    if(HWNDParent!=NULL)
        leParent=HWNDParent->getHwnd();
    INITCOMMONCONTROLSEX InitCtrlEx;
    InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
	InitCtrlEx.dwICC  = ICC_PROGRESS_CLASS;
	InitCommonControlsEx(&InitCtrlEx);
    InitCommonControls();
    hWnd=CreateWindowEx(0, PROGRESS_CLASS, (LPTSTR) 0, WS_CHILD | WS_VISIBLE | PBS_SMOOTH ,
                      x, y, largeur, hauteur,  leParent, NULL, hInstance, NULL);
    FinalInit();
}

/** @brief cProgressbar
  *
  * @todo: document this function
  */
 cProgressbar::cProgressbar(cHwnd * hwndParent,int largeur,int hauteur,cHwnd * HWNDParent):
        cControl(hwndParent)
{
    HWND leParent=hwndParent->getHwnd();
    if(HWNDParent!=NULL)
        leParent=HWNDParent->getHwnd();

    RECT rectangle;
    GetClientRect(leParent,&rectangle);

    INITCOMMONCONTROLSEX InitCtrlEx;
	InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
	InitCtrlEx.dwICC  = ICC_PROGRESS_CLASS;
	InitCommonControlsEx(&InitCtrlEx);
    InitCommonControls();
    hWnd=CreateWindowEx(0, PROGRESS_CLASS, (LPTSTR) 0, WS_CHILD | WS_VISIBLE | PBS_SMOOTH ,
                      (rectangle.right/2)-(largeur/2), (rectangle.bottom/2)-(hauteur/2), largeur, hauteur,  leParent, NULL, hInstance, NULL);
    FinalInit();
}



cProgressbar::~cProgressbar()
{
    //dtor
    DestroyWindow(this->getHwnd());
}

/** @brief TraitementEvent
  *
  * @todo: document this function
  */
bool cProgressbar::TraitementEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,LRESULT & resultat)
{
    return false;
}


void cProgressbar::StepIt()
{

    SendMessage(this->getHwnd(), PBM_STEPIT, 0,0);
    UpdateWindow(this->getHwnd());
}


void cProgressbar::SetStep(unsigned int step)
{
    SendMessage(this->getHwnd(), PBM_SETSTEP, (WPARAM)step,0);
}

void cProgressbar::CenterIt()
{
        HWND parent=GetParent(this->getHwnd());
        RECT rectangle,rectanglecourant;

        GetClientRect(parent,&rectangle);
        GetClientRect(this->getHwnd(),&rectanglecourant);



        MoveWindow(this->getHwnd(),(rectangle.right/2)-(rectanglecourant.right/2),(rectangle.bottom/2)-(rectanglecourant.bottom/2),rectanglecourant.right,rectanglecourant.bottom,true);
        UpdateWindow(parent);
}

void cProgressbar::SetRange(unsigned int mini,unsigned int maxi)
{
    SendMessage(this->getHwnd(), PBM_SETRANGE32, mini, maxi);
}



